/*
 * FileOutput.scala
 */

package acorn.jash.io

import acorn.jash.{Output,Shell}

import java.io.{BufferedWriter => BW,
                FileWriter => FW,
                PrintWriter => PW}

class FileOutput(val fn:String) extends Output {
  def put(arg:String) {
    writeWith{writer print arg}
  }

  def putln(arg:String) {
    writeWith{writer println arg}
  }

  def writeWith(pr: => Unit) {
    pr; writer flush; writer close
  }

  lazy val writer = {
    val file = Shell.wd.changeTo(fn).asFile
    new PW(new BW(new FW(file)))
  }
}
